This Python program reads 10 numbers into an array.
Then it reads a number between 1 and 10 and rotates the array to the left by that amount.
In a left rotation, the first elements move to the end of the array.
def rotate_left(arr: list[int], n: int) -> list[int]:
n = n % len(arr)
return arr[n:] + arr[:n]
# Read array from user
raw_input = input("Enter 10 numbers separated by space: ")
numbers = list(map(int, raw_input.strip().split()))
if len(numbers) != 10:
print("You must enter exactly 10 numbers.")
else:
k = int(input("Enter rotation count (1 to 10): "))
if not (1 <= k <= 10):
print("Rotation count must be between 1 and 10.")
else:
rotated = rotate_left(numbers, k)
print(f"\nArray after {k} left rotations:")
print(" ".join(map(str, rotated)))
Input: 1 2 3 4 5 6 7 8 9 10
Rotation count: 3
Output:
Array after 3 left rotations: 4 5 6 7 8 9 10 1 2 3